﻿@using System.Web.Script.Serialization
@{
    ViewBag.Title = "List";
}

<h2>List</h2>

    <!-- ko foreach: Friends-->
    <div>
        <span data-bind="text:FriendName"></span>
        <span data-bind="text:FriendLogo"></span>
    </div>
<!-- /ko -->

@{
    var model = ViewBag.Model;
    var jsonStr = new HtmlString(new JavaScriptSerializer().Serialize(model));
}

@section scripts
{

    
    
    <script>
        
        var init = @jsonStr;

        function FriendShipListItemModel(friendName, friendLogo) {

            var self = this;
            self.FriendName = ko.observable(friendName);
            self.FriendLogo= ko.observable(friendLogo);
        }

        function FriendShipListModel() {

            var self = this;
            var tempFriends =  $.isEmptyObject(init.Friends) ? [] : $.map(init.Friends, function(a) {
                return new FriendShipListItemModel(a.FriendName, a.FriendLogo);
            });

            self.Friends= ko.observableArray(tempFriends);
          
        }

        var vm = new FriendShipListModel();
        ko.applyBindings(vm);
    </script>

}